<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改答题记录')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-notes-edit" th:object="${notes}">
            <h4 class="form-header h4">答题记录信息</h4>
            <input name="notesId" th:field="*{notesId}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">问卷主键：</label>
                <div class="col-sm-8">
                    <input name="questionnaireId" th:field="*{questionnaireId}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">答题人主键：</label>
                <div class="col-sm-8">
                    <input name="userId" th:field="*{userId}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">答题人姓名：</label>
                <div class="col-sm-8">
                    <input name="userName" th:field="*{userName}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">总分：</label>
                <div class="col-sm-8">
                    <input name="totalScore" th:field="*{totalScore}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">答题时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="answerTime" th:value="${#dates.format(notes.answerTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">租户主键：</label>
                <div class="col-sm-8">
                    <input name="tenantId" th:field="*{tenantId}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">答题来源[001答题测试 002 课题方案 ]：</label>
                <div class="col-sm-8">
                    <input name="notesSource" th:field="*{notesSource}" class="form-control" type="text">
                </div>
            </div>
            <h4 class="form-header h4">答题记录项目信息</h4>
            <div class="row">
                <div class="col-sm-12">
                    <button type="button" class="btn btn-white btn-sm" onclick="addColumn()"><i class="fa fa-plus"> 增加</i></button>
                    <button type="button" class="btn btn-white btn-sm" onclick="sub.delColumn()"><i class="fa fa-minus"> 删除</i></button>
                    <div class="col-sm-12 select-table table-striped">
                        <table id="bootstrap-table"></table>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "qa/notes";
        $("#form-notes-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-notes-edit').serialize());
            }
        }

        $("input[name='answerTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $(function() {
            var options = {
                data: [[${notes.notesRecordList}]],
                pagination: false,
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                sidePagination: "client",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'index',
                    align: 'center',
                    title: "序号",
                    formatter: function (value, row, index) {
                    	var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                    	return columnIndex + $.table.serialNumber(index);
                    }
                },
                {
                    field: 'questionsId',
                    align: 'center',
                    title: '问卷题目主键',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='notesRecordList[%s].questionsId' value='%s'>", index, value);
                        return html;
                    }
				},
                {
                    field: 'answerIndex',
                    align: 'center',
                    title: '答案序号',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='notesRecordList[%s].answerIndex' value='%s'>", index, value);
                        return html;
                    }
				},
                {
                    field: 'answerName',
                    align: 'center',
                    title: '答案标签名',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='notesRecordList[%s].answerName' value='%s'>", index, value);
                        return html;
                    }
				},
                {
                    field: 'answerValue',
                    align: 'center',
                    title: '答案',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='notesRecordList[%s].answerValue' value='%s'>", index, value);
                        return html;
                    }
				},
                {
                    field: 'score',
                    align: 'center',
                    title: '得分',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='notesRecordList[%s].score' value='%s'>", index, value);
                        return html;
                    }
				
                }]
            };
            $.table.init(options);
        });

        function addColumn() {
            var count = $("#" + table.options.id).bootstrapTable('getData').length;
            sub.editColumn();
        	
            $("#" + table.options.id).bootstrapTable('insertRow', {
                index: count,
                row: {
                    index: $.table.serialNumber(count),
                    questionsId: "",
                    answerIndex: "",
                    answerName: "",
                    answerValue: "",
                    score: ""
        	    }
            });
        }
    </script>
</body>
</html>